package com.jams.goodox.activity.serve.meet;


import android.content.Intent;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.entity.MeetDateBean;
import com.jams.goodox.entity.resp.MeetCalendarResp;
import com.jams.goodox.net.RetrofitCallbackListener;
import com.jams.goodox.net.services.ServiceService;
import com.jams.goodox.utils.StyleUtil;
import com.jams.goodox.utils.ToastUtil;
import com.jams.goodox.utils.Utils;
import com.jams.goodox.widget.MeetCalendar;

import butterknife.Bind;
import retrofit2.Call;

/**
 * 会议日历
 * Created by jams_zhen on 2017/5/4.
 */

public class MeetCalendarActivity extends BaseActivity implements MeetCalendar.InterOnDateCheck {

    @Bind(R.id.meet_calender)
    MeetCalendar meetCalender;

    private MeetDateBean meetDateBean;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_meet_calender;
    }

    @Override
    protected void init() {
        StyleUtil.titleBackKey(this,"日历");
        String id=getIntent().getStringExtra("id");
        meetDateBean=(MeetDateBean)getIntent().getSerializableExtra("meetDateBean");
        getData(id);
    }

    /**
     * 获取日期数据
     */
    private void getData(String id){
        showLoading();
        enqueue(createCallService(ServiceService.class).getMeetCalendar(id), new RetrofitCallbackListener<MeetCalendarResp>() {
            @Override
            public void onSuccess(Call<MeetCalendarResp> call, MeetCalendarResp result) {
                misLoading();
                if(result.getData()==null)return;
                meetCalender.setMeetMonthList( Utils.getMeetAllLists(result.getData()));
                meetCalender.setInterOnDateCheck(MeetCalendarActivity.this);
                meetCalender.setCheckDate(meetDateBean);
            }

            @Override
            public void onError(String msg) {
                misLoading();
                ToastUtil.show(msg);
            }
        });
    }

    @Override
    public void onCalenderClick(MeetDateBean checkDate) {
        Intent in=new Intent();
        in.putExtra("meetDateBean",checkDate);
        setResult(RESULT_OK,in);
        finish();
    }
}
